package tws

import (
	"log"

	"github.com/gin-gonic/gin"
)

type UseFunc struct {
	handleFuncs []func() gin.HandlerFunc
}

func NewUseFunc() *UseFunc {
	return &UseFunc{}
}
func (_this *UseFunc) Add(handle func(ctx *gin.Context)) {
	if handle == nil {
		log.Fatal("func is nil")
		return
	}
	h := func() gin.HandlerFunc {
		return func(ctx *gin.Context) {
			handle(ctx)
		}
	}
	_this.handleFuncs = append(_this.handleFuncs, h)
}

func (_this *UseFunc) Do(engine *gin.Engine) {
	for _, handle := range _this.handleFuncs {
		engine.Use(handle())
	}
}
func (_this *UseFunc) GetHandleFuncs() []func() gin.HandlerFunc {
	return _this.handleFuncs
}
